package com.liu.demo6.controller;

import com.liu.demo6.Mapper.StudentMapper;
import com.liu.demo6.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
public class StudentController {
    @Autowired
    private StudentMapper studentMapper;

    @GetMapping(value = "/student/{id}")
    public Student getStudentById(@PathVariable("id") int id) {
        return studentMapper.findById(id);
    }

    // 根据id删除学生信息（DELETE请求）
    @DeleteMapping(value = "/student/{id}")
    public ResponseEntity<String> deleteStudent(@PathVariable("id") int id) {
        int result = studentMapper.deleteStudent(id);
        if (result > 0) {
            return ResponseEntity.ok("学生信息删除成功");
        } else {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("删除学生信息失败");
        }
    }
}